#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver import firefox


class FirforDriverConfig:
    def driver_config(self, root_path='./'):
        """
        浏览器驱动
        :return:
        """
        # 自动下载驱动
        # path = GeckoDriverManager().install()
        # s = Service(path)
        s = Service(executable_path=root_path + 'configuration/geckodriver.exe')
        options = Options()
        # options.add_argument("window-position=0,0")
        # options.add_argument("start-maximized")
        # options.add_argument("--ignore-certificate-errors")
        # # 允许忽略localhost上的TLS/SSL错误
        # options.add_argument("--allow-insecure-localhost")
        # # 设置为无痕模式
        # options.add_argument("--incognito")
        # # 解决卡顿
        # options.add_argument("--disable-gpu")
        # options.add_argument("--no-sandbox")
        # options.add_argument("--disable-dev-shm-usage")
        # options.add_argument('--disable-infobars')  # 不显示 chrome正受到自动测试软件的控制。
        # ## 禁用弹出拦截
        # options.add_argument("--disable-popup-blocking")
        driver = webdriver.Firefox(service=s, options=options)
        # 删除所有cookies
        driver.delete_all_cookies()
        # 设置为全屏模式
        driver.maximize_window()
        return driver
